package mydate;


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 第三代日期 jdk8引入
 * @author Raymond
 * @create 2025/4/23 15:14
 */
public class myLocalDateTime {
    public static void main(String[] args) {
        //时间+日期  LocalDate=>时间  LocalTime=>日期
        LocalDateTime now = LocalDateTime.now();
        System.out.println("now = " + now);
        System.out.println("now.getYear() = " + now.getYear());
        System.out.println("now.getMonth() = " + now.getMonth());
        System.out.println("now.getDayOfMonth() = " + now.getDayOfMonth());
        System.out.println("now.getHour() = " + now.getHour());
        System.out.println("now.getMinute() = " + now.getMinute());
        System.out.println("now.getSecond() = " + now.getSecond());


        //时间格式化
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(now);
        System.out.println("format = " + format);

        //可以对时间进行加减 plus and minus
        System.out.println("now.plusDays(2) = " + now.plusDays(2));
    }
}
